import java.util.*;

/**
 * @Author 12629
 * @Description：
 */
class Student implements Comparable<Student>{

    @Override
    public int compareTo(Student o) {
        return 0;
    }
}
public class Test {

    //
    public static void func1(int[] array) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            set.add(array[i]);
        }
        System.out.println(set);
    }

    public static int func2(int[] array) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            if(!set.contains(array[i])) {
                set.add(array[i]);
            }else {
                return array[i];
            }
        }
        return -1;
    }

    public static void func3(int[] array) {
        //key:关键字   val:次数
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < array.length; i++) {
            int key = array[i];
            if(map.get(key) == null) {
                map.put(key,1);
            }else {
                int val = map.get(key);//1
                map.put(key,val+1);
            }
        }
        System.out.println(map);
    }


    public static void main(String[] args) {
        int[] array = new int[10_0000];
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(5_000);
        }
        func3(array);
       //System.out.println(func2(array));
    }

    public static void main5(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("abc");
        System.out.println(set);
        Set<String> set2 = new HashSet<>();
    }


    public static void main4(String[] args) {
        //可以存储null key  value = null
        Map<String,Integer> map = new HashMap<>();
        map.put("hello",3);
        map.put("abc",10);
        map.put(null,null);
        map.put(null,8);

        System.out.println("打印hashmap: "+map);

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> entry : entrySet) {
            System.out.println("key: "+entry.getKey()+" val:" + entry.getValue());
        }
        System.out.println("s==================");
        Collection<Integer> list = map.values();
        System.out.println(list);
    }


    public static void main3(String[] args) {
        Map<String,Integer> map = new TreeMap<>();
        map.put("abc",10);
        map.put("hello",3);
        map.put("hello2",8);

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> entry : entrySet) {
            System.out.println("key: "+entry.getKey()+" val:" + entry.getValue());
        }
        System.out.println("s==================");
        Collection<Integer> list = map.values();
        System.out.println(list);

         /*//返回所有key的集合
        Set<String> set = map.keySet();
        System.out.println(set);*/


        /*
        System.out.println(map.get("hello"));
        System.out.println(map.get("hellogaobo"));
        System.out.println(map.getOrDefault("hellogaobo",100));*/



        //Map<Student,Integer> map2 = new TreeMap<>();

        //map2.put(null,1);



    }

    public static void main2(String[] args) {
        Map<String,Integer> map = new TreeMap<>();
        Map<String,Integer> map2 = new HashMap<>();


        Set<String> set = new TreeSet<>();
        Set<String> set2 = new HashSet<>();


    }

    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        int[] array = {80,30,48,60,90,56};
        for (int i = 0; i < array.length; i++) {
            binarySearchTree.insert(array[i]);
        }
        System.out.println("======");
        binarySearchTree.remove(30);
        binarySearchTree.remove(80);
        System.out.println("==========");
        binarySearchTree.inorder(binarySearchTree.root);
    }
}
